<!-- Copyright (c) 2022 渝州大数据实验室
 *
 * Lanius is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 -->
<!-- 
* @desc:运行监控页面
* @fileName:Dashboard.vue
* @author:zoujunjie
* @date:2022-4-7
!-->
<template>
  <div class="group">
    <div class="title">任务实例</div>
    <el-divider />
    <div class="card-list">
      <TaskInstanceCards :data="taskInstanceDataList"></TaskInstanceCards>
    </div>
  </div>
  <div class="group">
    <div class="title">资源管理</div>
    <el-divider />
    <div class="card-list">
      <ResourceManagementCards :data="resourceData"></ResourceManagementCards>
    </div>
  </div>
  <div class="group">
    <div class="title">任务编排</div>
    <el-divider />
    <div class="card-list">
      <TaskArrangementCards :data="taskArrangeDataList"></TaskArrangementCards>
    </div>
  </div>
</template>
<script setup lang="ts">
import TaskInstanceCards from "./components/TaskInstanceCards.vue";
import TaskArrangementCards from "./components/TaskArrangementCards.vue";
import ResourceManagementCards from "./components/ResourceManagementCards.vue";
import { HttpClient } from "@/common/http";
import { onMounted, ref } from "vue";
import { showErrorMessage } from "@/common/message";

const http = new HttpClient();
let taskInstanceDataList = ref([]);
let taskArrangeDataList = ref([]);
let resourceData = ref({});

onMounted(() => {
  http
    .get({
      url: "/scheduler/view/statistics",
    })
    .then((r: any) => {
      taskInstanceDataList.value = r.data.schedulerViewTaskInstance;
      taskArrangeDataList.value = r.data.schedulerViewTaskPlan;
    })
    .catch((err) => {
      console.log("catch", err);
      showErrorMessage({
        message: err?.data,
      });
    });

  http
    .get({
      url: "/resource/statistic/getStatusStatistic",
    })
    .then((r: any) => {
      resourceData.value = r.data;
    })
    .catch((err) => {
      console.log("catch", err);
      showErrorMessage({
        message: err?.data,
      });
    });
});
</script>
<style lang="scss" scoped>
.group {
  .title {
    font-weight: 700;
    color: #333333;
    font-size: 16px;
    line-height: 22px;
    margin-bottom: -10px;
  }

  .card-list {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    margin-right: -20px;
  }
}
</style>
